from pint import UnitRegistry
from numpy import ndarray
from pint import Quantity

unit = UnitRegistry()
unit.define('zonal_wavenumber = 2.4953202e-08 / m')

Q_ = unit.Quantity

def _handle_quantity(value: Quantity | ndarray | float | int, units: str) -> Quantity:
    """处理输入的值，如果没有单位，则加上 unit，如果有单位，则转换为 unit。
    """
    if isinstance(value, (int, float, ndarray)):
        value = Q_(value, unit(units))
    elif not isinstance(value, Quantity):
        raise TypeError("input value must be a Quantity, ndarray or float")
    return value.to(units)